package com.ys.shop.control;

import com.ys.shop.dao.UserDAOImp;
import com.ys.shop.factory.DaoFactoryImp;
import com.ys.shop.vo.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "RegServlet")
public class RegServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter printWriter=response.getWriter();
        printWriter.print("qwerqwet");
        //获取数据
        String name=request.getParameter("userName");
        String pass=request.getParameter("passWord");
        //封装
        Users u=new Users();
        u.setEu_user_id("002");
        u.setEu_user_name(name);
        u.setEu_password(pass);
        boolean a=false;
        try {
            UserDAOImp userDAOImp= (UserDAOImp) DaoFactoryImp.getInstance().createDAO("userdao");
            a=userDAOImp.insert(u);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (a){
//            request.getRequestDispatcher("Success.jsp").forward(request,response);
            printWriter.print("注册成功！");
        }else{
//            request.getRequestDispatcher("Erroy").forward(request,response);
            printWriter.print("注册失败！");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
